//
//  SAPaperSetFootView.m
//  saasRetail
//
//  Created by 黄志刚 on 2022/5/13.
//

#import "SAPaperSetFootView.h"
#import "SAPaperSetModel.h"

@interface SAPaperSetFootView ()

@property (nonatomic, strong) UIButton *previewBtn;
@property (nonatomic, strong) UIButton *selectBtn;
@property (nonatomic, strong) UILabel *titleLab;

@end

@implementation SAPaperSetFootView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAPaperSetModel *)model {
    _model = model;
    self.selectBtn.selected = model.isSelect;
}

#pragma mark - event
-(void)clickedPreviewBtn {
    !self.previewBlock ?: self.previewBlock();
}

-(void)clickedSelectBtn {
    self.model.isSelect = !self.model.isSelect;
    self.selectBtn.selected = self.model.isSelect;
    !self.HKBlock ?: self.HKBlock();
}

#pragma mark - initUI
-(void)initUI {
    UIView *whiteView = [[UIView alloc] initWithFrame:SARectMake(0, 0, kBaseScreenWidth, 45)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:whiteView];
    
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.selectBtn];
    [self.contentView addSubview:self.previewBtn];
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(60, 0, 100, 45)];
        _titleLab.textColor = kBlackColor;
        _titleLab.text = @"显示港元";
        _titleLab.font = kFont(16);
    }
    return _titleLab;
}


-(UIButton *)selectBtn {
    if (!_selectBtn) {
        _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _selectBtn.frame = SARectMake(0, 0, 60, 45);
        [_selectBtn setImage:[UIImage imageNamed:@"shop_blueRound2"] forState:UIControlStateNormal];
        [_selectBtn setImage:[UIImage imageNamed:@"shop_blueCheck2"] forState:UIControlStateSelected];
        [_selectBtn addTarget:self action:@selector(clickedSelectBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectBtn;
}

-(UIButton *)previewBtn {
    if (!_previewBtn) {
        _previewBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_previewBtn setTitle:@"预览效果" forState:UIControlStateNormal];
        [_previewBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _previewBtn.frame = CGRectMake(kScaleNum(99), kScaleNum(80), kScaleNum(177), kScaleNum(40));
        _previewBtn.titleLabel.font = kFont(18);
        _previewBtn.layer.cornerRadius = kScaleNum(3);
        _previewBtn.layer.masksToBounds = YES;
        [_previewBtn addTarget:self action:@selector(clickedPreviewBtn) forControlEvents:UIControlEventTouchUpInside];
        _previewBtn.backgroundColor = kBuleColor;
    }
    return _previewBtn;
}

@end
